#pragma once

void make_pion(colorcolorspinspin *S)
{
  printf("P5P5\n");
  printf(" t   Real  Imag \n");
  spinspin s,sdag;
  //sum in space
  for (int t=0; t<T; t++){

        complex c=0;

        for (int x=0; x<L; x++)   for (int y=0; y<L; y++)    for (int z=0; z<L; z++)
             {
                 int dest=z+L*(y+L*(x+L*t));
                // sum colorcolor
                 for (int ic1=0; ic1<3; ic1++)  for (int ic2=0; ic2<3; ic2++){
                              // s and sdag at each color indices and point
                              for (int is1=0; is1<4; is1++)   for (int is2=0; is2<4; is2++)
                              {
                                                s[is1][is2]=S[dest][ic1][ic2][is1][is2];
                                                sdag[is1][is2]=conj(S[dest][ic1][ic2][is2][is1]);
                               }
                               //contraction
                               complex ctemp;
                               ctemp=0;
                               for (int is1=0; is1<4; is1++)  for (int is2=0; is2<4; is2++)
                                                ctemp=ctemp+s[is1][is2]*sdag[is2][is1];
                                //accumulate
                                c=c+ctemp;
                        }
                }

        printf("%d %8.16f %8.16f\n", t, creal(c), cimag(c));
   }
}
